﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;


namespace ForexHistory
{
    public struct Tick : IComparable
    {
        private DateTime _tickTime;

        public DateTime TickTime
        {
            get { return _tickTime; }
            set { _tickTime = value; }
        }

        private int _order;

        public int Order
        {
            get { return _order; }
            set { _order = value; }
        }

        private int _rateBid;

        public int RateBidRaw
        {
            get { return _rateBid; }
            set { _rateBid = value; }
        }
        private int _rateAsk;

        public int RateAskRaw
        {
            get { return _rateAsk; }
            set { _rateAsk = value; }
        }

        public decimal RateBid
        {
            get
            {
                return Convert.ToDecimal(_rateBid) / 10000m;
            }
        }

        public decimal RateAsk
        {
            get
            {
                return Convert.ToDecimal(_rateAsk) / 10000m;
            }
        }

        public int CompareTo(object obj)
        {
            if (obj == null) return 1;

            Tick other = (Tick)obj;

            if (other.TickTime.Year == 0001)
                return 1;

            if (this.TickTime == other.TickTime && this.RateAskRaw == other.RateAskRaw && this.RateBidRaw == other.RateBidRaw && this.Order == other.Order)
                return 0;
            else if (this.TickTime == other.TickTime)
            {
                if (this.Order > other.Order)
                    return 1;
                else
                    return -1;
            }
            else if (this.TickTime > other.TickTime)
                return 1;
            else
                return -1;

        }

        public int DateCompareTo(object obj)
        {
            if (obj == null) return 1;

            Tick other = (Tick)obj;

            if (other.TickTime.Year == 0001)
                return 1;

            if (this.TickTime == other.TickTime)
                return 0;
            else if (this.TickTime > other.TickTime)
                return 1;
            else
                return -1;

        }

    }


    public class FullCompare : IComparer<Tick>
    {
        
        public  int Compare(Tick x, Tick y)
        {
            return x.CompareTo(y);           
        }
    }

    public class DateCompare : IComparer<Tick>
    {

        public int Compare(Tick x, Tick y)
        {
            return x.DateCompareTo(y);
        }
    }
}
